package com.meida.module.bus.provider.api.util;

import cn.hutool.core.io.IoUtil;
import com.google.common.collect.Lists;
import com.meida.module.bus.client.entity.BusWbsBudget;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
//import org.jxls.common.Context;
//import org.jxls.util.JxlsHelper;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

@Component
@Slf4j
public class PmsFileUtil {
    /**
     * 输出模板类型数据
     * @param tmpPath 模板路径
     * @param exportCon 输出内容
     * @param tmpFileNm 模板文件名
     * @param exportFileNm 输出文件名
     * @param response response
     *
     */
    @ApiOperation("输出模板类型数据")
    public void exportFile(String tmpPath, Object exportCon, String tmpFileNm, String exportFileNm, HttpServletResponse response) {
//        InputStream is = null;
//        OutputStream os = null;
//        ServletOutputStream sout = null;
//        try {
//            is = new FileInputStream(tmpPath + tmpFileNm);
//            os = new FileOutputStream(tmpPath + exportFileNm);
//            Context context = new Context();
//            List<BusWbsBudget> busWbsBudgetList = Lists.newArrayList();
//            BusWbsBudget tt = new BusWbsBudget();
//            tt.setPosid("123");
//            busWbsBudgetList.add(tt);
//            context.putVar("DATA", exportCon);
//
//            //当循环的表体为javabean时指定读取的属性，Sheet2!A1表示输出开始的位置
//            JxlsHelper.getInstance().processTemplate(is, os, context);
//            response.reset();
//            response.setContentType("application/x-msdownload;charset=utf-8");
//            //下载文件的名称
//            response.setHeader("Content-Disposition", "attachment;filename=" + new String((exportFileNm).getBytes("gbk"), "iso-8859-1"));
//            sout = response.getOutputStream();
//            byte[] bytes = cn.hutool.core.io.FileUtil.readBytes(tmpPath + exportFileNm);
//            sout.write(bytes);
//            IoUtil.close(sout);
//
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        } finally {
//            if (is != null) {
//                IoUtil.close(is);
//            }
//            if (os != null) {
//                IoUtil.close(os);
//            }
//            if (sout != null) {
//                IoUtil.close(sout);
//            }
//        }
    }
}
